package com.ylbh.modules.cashaudit.controller;

import com.ylbh.common.annotation.SysLog;
import com.ylbh.common.exception.NormalException;
import com.ylbh.common.pojo.businessorder.vo.NewBusinessOrderDetailsVO;
import com.ylbh.common.pojo.cashaudit.dto.CashAuditPassDTO;
import com.ylbh.common.pojo.cashaudit.dto.CashAuditDTO;
import com.ylbh.common.pojo.cashaudit.dto.MerchantIncomeListDTO;
import com.ylbh.common.pojo.cashaudit.vo.DetailsOfEarningsAndExtensionVO;
import com.ylbh.common.pojo.cashaudit.vo.DetailsOfEarningsAndOnLineVO;
import com.ylbh.common.pojo.cashaudit.vo.DetailsOfEarningsAndUnderTheLineVO;
import com.ylbh.common.pojo.cashaudit.vo.DetailsOfPresentationVO;
import com.ylbh.common.utils.CommonResult;
import com.ylbh.common.utils.PageDTO;
import com.ylbh.common.utils.PageUtils;
import com.ylbh.common.utils.Ref;
import com.ylbh.modules.cashaudit.service.BusinessWithRecordService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 财务 ->提现审核
 * @author czx
 * @date 2019-05-04 09:57:58
 */
@RestController
@RequestMapping("user/cashAudit")
public class CashAuditController {

    @Autowired
    private BusinessWithRecordService businessWithRecordService;

    @ApiOperation("提现审核列表")
    @RequestMapping("queryCashAuditList")
    @RequiresPermissions("user:cashAudit:queryCashAuditList")
    public CommonResult<PageUtils> queryCashAuditList(CashAuditDTO cashAuditDTO) {
        PageUtils list = businessWithRecordService.queryCashAuditList(cashAuditDTO);
        return Ref.ok(list);
    }

    @ApiOperation("待提现审核的记录数")
    @RequestMapping("queryWithRecordCount")
    public CommonResult<Integer> queryWithRecordCount() {
        Integer count = businessWithRecordService.queryWithRecordCount();
        return Ref.ok(count);
    }

    @ApiOperation("周-月提现列表")
    @RequestMapping("queryWeekCashWithdrawalList")
    @RequiresPermissions("user:cashAudit:queryWeekCashWithdrawalList")
    public CommonResult<PageUtils> queryWeekCashWithdrawalList(CashAuditDTO cashAuditDTO) {
        PageUtils list = businessWithRecordService.queryWeekAndMonthCashWithdrawalList(cashAuditDTO);
        return Ref.ok(list);
    }

    @SysLog("提现审核操作")
    @ApiOperation("提现审核操作")
    @RequestMapping("modifyCashAudit")
    @RequiresPermissions("user:cashAudit:modifyCashAudit")
    public CommonResult<Void> modifyCashAudit(@RequestBody CashAuditPassDTO cashAuditPassDTO) {
        businessWithRecordService.modifyCashAudit(cashAuditPassDTO);
        return Ref.ok();
    }

    @ApiOperation("提现审核详情")
    @RequestMapping("getDetailsOfPresentation/{id}")
    public CommonResult<DetailsOfPresentationVO> getDetailsOfPresentation(@PathVariable(value = "id")Long id) {
        DetailsOfPresentationVO vo = businessWithRecordService.getDetailsOfPresentation(id);
        return Ref.ok(vo);
    }

    @ApiOperation("提现审核详情子订单信息")
    @RequestMapping("getSonOrderDetailsById/{id}")
    public CommonResult<PageUtils> getSonOrderDetailsById(@PathVariable String id, PageDTO pageDTO) {
        PageUtils list = businessWithRecordService.getSonOrderDetailsById(id, pageDTO);
        return Ref.ok(list);
    }

    @ApiOperation("商家收益列表")
    @RequestMapping("queryMerchantIncomeList")
    public CommonResult<PageUtils> queryMerchantIncomeList(MerchantIncomeListDTO merchantIncomeListDTO) {
        PageUtils list = businessWithRecordService.queryMerchantIncomeList(merchantIncomeListDTO);
        return Ref.ok(list);
    }

    @ApiOperation("商家收益详情-线上")
    @RequestMapping("getDetailsOfEarningsAndOnLineById/{id}")
    public CommonResult<DetailsOfEarningsAndOnLineVO> getDetailsOfEarningsAndOnLineById(@PathVariable(value = "id")Long id) {
        DetailsOfEarningsAndOnLineVO vo = businessWithRecordService.getDetailsOfEarningsAndOnLineById(id);
        return Ref.ok(vo);
    }

    @ApiOperation("商家收益详情-线下")
    @RequestMapping("getDetailsOfEarningsAndUnderTheLineById/{id}")
    public CommonResult<DetailsOfEarningsAndUnderTheLineVO> getDetailsOfEarningsAndUnderTheLineById(@PathVariable(value = "id")Long id) {
        DetailsOfEarningsAndUnderTheLineVO vo = businessWithRecordService.getDetailsOfEarningsAndUnderTheLineById(id);
        return Ref.ok(vo);
    }

    @ApiOperation("商家收益详情-推广")
    @RequestMapping("getDetailsOfEarningsAndExtensionById/{id}")
    public CommonResult<DetailsOfEarningsAndExtensionVO> getDetailsOfEarningsAndExtensionById(@PathVariable(value = "id")Long id) {
        DetailsOfEarningsAndExtensionVO vo = businessWithRecordService.getDetailsOfEarningsAndExtensionById(id);
        return Ref.ok(vo);
    }

    @ApiOperation("提现审核列表导出")
    @RequestMapping("cashAuditExcel")
    public CommonResult<Void> cashAuditExcel(HttpServletRequest request, HttpServletResponse response) throws NormalException {
        businessWithRecordService.cashAuditExcel(request, response);
        return Ref.ok();
    }

    @ApiOperation("提现详情")
    @GetMapping("getOrderDetails/{no}/{type}")
    public CommonResult getOrderDetails(@PathVariable String no, @PathVariable Integer type) {
        NewBusinessOrderDetailsVO vo = businessWithRecordService.getOrderDetails(no, type);
        return Ref.ok(vo);
    }
}
